<?php

namespace Mem;

use MemLib\MemBase;
use MemLib\Pdb;
/*
 *  meta_key:
    考试类型 exam_type        1：阶段考核 2：期末考核
    考试时长 exam_time 单位秒
    考核题目数量 exam_count
    每题分数 each_score
    设置合格分数 passing_score
    补考次数 make_up_times
    考核范围 exam_range
    考核试题(随堂问答错题)占比 err_percent
    考核试题(本次考核试题)占比 exam_percent
    展示问题解析 is_analysis         1：是  0：否
    展示综合评分 is_grade	         1：是  0：否
*
*/

class MemOrder_info_meta extends MemBase
{

    public function __construct()
    {
        parent::__construct(Pdb::db_order, "t_order_info_meta");
    }

    /**
     * 添加数据
     * @param mixed $order_id 节课ID
     * @param mixed $meta_key 数据名
     * @param mixed $meta_value 数据值
     * @param mixed $remark
     */
    public function insertDataWithParam($order_id, $meta_key, $meta_value, $remark)
    {
        $order_id = (int)$order_id;
        $meta_key = \MemLib\PublicFunc::convertToHtml($meta_key);
        $meta_value = \MemLib\PublicFunc::convertToHtml($meta_value);
        $data = array(
            'order_id' => $order_id,
            'meta_key' => $meta_key,
            'meta_val' => $meta_value,
            'remark' => $remark,
            'insert_dt' => date("Y-m-d H:i:s")
        );
        $res = $this->addData($data);
        return $this->getTmpID();
    }


    public function insertDataWithData($order_id, $data)
    {
        $order_id = (int)$order_id;
        foreach ($data as $val) {
            $arr = array();
            foreach ($val as $k => $v) {
                $meta_key = \MemLib\PublicFunc::convertToHtml($k);
                $meta_value = \MemLib\PublicFunc::convertToHtml($v);
                $arr[$meta_key] = $meta_value;
            }
            if (!empty($arr)) {
                $arr["insert_dt"] = date("Y-m-d H:i:s");
                $arr["order_id"] = $order_id;
                $res = $this->addData($arr);
            }
        }
        return $this->getTmpID();
    }

    /**
     * 根据$order_id 获取数据
     * @param mixed $order_id
     */
    public function getDataWithorder_id($order_id)
    {
        $order_id = (int)$order_id;
        $sql = "SELECT * FROM t_order_info_meta WHERE order_id='{$order_id}' ORDER  BY insert_dt DESC ;";
        $data = $this->getData($sql, "getDataWithorder_id:{$order_id}");
        return $data;
    }

    /**
     * 删除
     * @param $wheredata
     */
    public function delDataWithList_id($wheredata)
    {
        $ret = $this->deleteData($wheredata);
        return  $ret;
    }
}
